package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* HelpView
* */
class HelpView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            style = Paint.Style.STROKE
            strokeCap = Paint.Cap.ROUND
            strokeJoin = Paint.Join.ROUND
            color = context.resources.getColor(R.color.color_ee000000)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            color = context.resources.getColor(R.color.color_ee000000)
        }
    }

    private val mPath0 by lazy {
        Path()
    }

    private val offsetAngle = 45F

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            save()
            translate(cx, cy)

            val mStrokeWidth = (cx * 1 / 12).coerceAtLeast(minStrokeWidth / 2)
            mPaint0.strokeWidth = mStrokeWidth

            mPath0.apply {
                reset()
                arcTo(
                    -cx * 3 / 12,
                    -cy * 9 / 12,
                    cx * 3 / 12,
                    -cy * 3 / 12,
                    245F - offsetAngle,
                    205 + offsetAngle,
                    false
                )
                lineTo(0F, cy * 5 / 12)
            }
            drawPath(mPath0, mPaint0)

            val radius = (cy * 1 / 12).coerceAtLeast(minStrokeWidth / 2)
            drawCircle(
                0F,
                cy * 8 / 12 ,
                radius,
                mPaint1
            )

            restore()
        }
    }
}